/*
 * @Description: 档案征集管理功能
 * @Author: Zzt
 * @Date: 2022-12-28 11:23:48
 * @LastEditTime: 2023-01-06 19:19:17
 */

import { Button, Divider, Space } from 'antd';
import { useLibraryCollectionContext } from '../../contexts/LibraryCollectionContext';
import ImportBtn from '../optBtns/ImportBtn';
import AddLibraryItem from '../optBtns/AddLibraryItem';
import { EnumInitRepoName } from '@/view/system/LIBManage/dictionaries';
import ExportOpt from '../optBtns/ExportOpt';
import { useMemo } from 'react';
import PrintBtn from '../optBtns/PrintBtn';
import Circulation from '../optBtns/Circulation';
import { isNullObj } from '@/utils';

interface IRecordOperatesProps {
  selectItems: number[];
}
const dbName = EnumInitRepoName.Collection;
const RecordOperates = (props: IRecordOperatesProps) => {
  const { selectItems } = props;
  const { selectAT, deleteItem } = useLibraryCollectionContext();

  const circulation = useMemo(
    () =>
      !isNullObj(selectAT) && (
        <Circulation selectItems={selectItems} baseInfo={{ ...selectAT, dbName: 'collection' }} />
      ),
    [selectAT, selectItems]
  );

  return (
    <>
      <Space size="small">
        <AddLibraryItem
          coordinate={{
            atCode: selectAT?.atCode,
            atType: selectAT?.atType,
            level: selectAT?.atLevel
          }}
          onSave={undefined}
        />
        <Button disabled={selectItems.length < 2}>批量修改</Button>
        <Button
          disabled={selectItems.length === 0}
          onClick={() =>
            deleteItem(1, {
              atCode: selectAT?.atCode,
              atType: selectAT?.atType,
              level: selectAT?.atLevel,
              entryIdList: selectItems,
              commonParams: {
                dbName
              }
            })
          }
        >
          删除
        </Button>
        <PrintBtn selectItems={selectItems} selectAt={selectAT} />
        <Button disabled>检测</Button>
        <Button disabled>查重</Button>
        <ImportBtn batchData={selectAT} />
        <ExportOpt
          info={{ ...selectAT, levelName: '', dbName: 'collection', fondId: selectAT.fondsId }}
          selectItems={selectItems}
        />
        {circulation}
        <Divider type="vertical" />
        <Button>筛选检索</Button>
      </Space>
    </>
  );
};
export default RecordOperates;
